import type { Linter } from 'eslint';

const restrictedImportIgnores = ['**/vite.config.mts', '**/tailwind.config.mjs', '**/postcss.config.mjs'];

const customConfig: Linter.Config[] = [
    // shadcn-ui 内部组件是自动生成的，不做太多限制
    {
        files: ['packages/@core/ui-kits/base/**/**'],
        rules: {
            'vue/require-default-prop': 'off',
        },
    },
    {
        files: ['apps/**/**', 'packages/framework/**/**', 'packages/plugins/**/**'],
        ignores: restrictedImportIgnores,
        rules: {
            'perfectionist/sort-interfaces': 'off',
            'perfectionist/sort-objects': 'off',
        },
    },
    {
        files: ['**/**.vue'],
        ignores: restrictedImportIgnores,
        rules: {
            'perfectionist/sort-objects': 'off',
        },
    },
    {
        // apps内部的一些基础规则
        files: ['apps/**/**'],
        ignores: restrictedImportIgnores,
        rules: {
            'no-restricted-imports': [
                'error',
                {
                    patterns: [
                        {
                            group: ['#/api/*'],
                            message: 'The #/api package cannot be imported, please use the @core package itself',
                        },
                        {
                            group: ['#/layouts/*'],
                            message: 'The #/layouts package cannot be imported, please use the @core package itself',
                        },
                        {
                            group: ['#/locales/*'],
                            message: 'The #/locales package cannot be imported, please use the @core package itself',
                        },
                        {
                            group: ['#/stores/*'],
                            message: 'The #/stores package cannot be imported, please use the @core package itself',
                        },
                    ],
                },
            ],
            'perfectionist/sort-interfaces': 'off',
        },
    },
    {
        // @core内部组件，不能引入@croco/* 里面的包
        files: ['packages/@core/**/**'],
        ignores: restrictedImportIgnores,
        rules: {
            'no-restricted-imports': [
                'error',
                {
                    patterns: [
                        {
                            group: ['@croco/*'],
                            message: 'The @core package cannot import the @croco package, please use the @core package itself',
                        },
                    ],
                },
            ],
        },
    },
    {
        // @core/shared内部组件，不能引入@croco/* 或者 @croco-core/* 里面的包
        files: ['packages/@core/base/**/**'],
        ignores: restrictedImportIgnores,
        rules: {
            'no-restricted-imports': [
                'error',
                {
                    patterns: [
                        {
                            group: ['@croco/*', '@croco-core/*'],
                            message: 'The @croco-core/shared package cannot import the @croco package, please use the @core/shared package itself',
                        },
                    ],
                },
            ],
        },
    },

    {
        // 不能引入@croco/*里面的包
        files: ['packages/styles/**/**', 'packages/plugins/**/**', 'packages/framework/**/**'],
        ignores: restrictedImportIgnores,
        rules: {
            'no-restricted-imports': [
                'error',
                {
                    patterns: [
                        {
                            group: ['@croco/*'],
                            message: 'The @croco package cannot be imported, please use the @core package itself',
                        },
                    ],
                },
            ],
        },
    },
    // 后端模拟代码，不需要太多规则
    {
        files: ['apps/backend-mock/**/**', 'docs/**/**'],
        rules: {
            '@typescript-eslint/no-extraneous-class': 'off',
            'n/no-extraneous-import': 'off',
            'n/prefer-global/buffer': 'off',
            'n/prefer-global/process': 'off',
            'no-console': 'off',
            'unicorn/prefer-module': 'off',
        },
    },
    {
        files: ['**/**/playwright.config.ts'],
        rules: {
            'n/prefer-global/buffer': 'off',
            'n/prefer-global/process': 'off',
            'no-console': 'off',
        },
    },
    {
        files: ['internal/**/**', 'scripts/**/**'],
        rules: {
            'no-console': 'off',
        },
    },
];

export { customConfig };
